﻿///////////////////////////////////////////////////////////////////////////////
// File:        ConnectionInputStream.hpp
// Author:      671643387@qq.com
// Description:
///////////////////////////////////////////////////////////////////////////////

#ifndef NIO_NET_CONNECTIONINPUTSTREAM_HPP_
#define NIO_NET_CONNECTIONINPUTSTREAM_HPP_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <boost/function.hpp>
#include <nio/net/ConnectionStream.hpp>

namespace nio
{
    namespace net
    {
        class ConnectionInputStream : public ConnectionStream
        {
        public:
            typedef ConnectionInputStream self;
        public:
            ConnectionInputStream(Socket& sock, unsigned int size = 1024 * 32);
            ConnectionInputStream(Socket& sock, ByteBuffer buff, unsigned int size = 1024 * 32);
            virtual ~ConnectionInputStream();

        public:
            int fill(void);

            unsigned int read(char* buf, unsigned int length)
            {
                return ConnectionStream::read(buf, length);
            }

            unsigned int peek(char* buf, unsigned int length)
            {
                return ConnectionStream::peek(buf, length);
            }

            unsigned int skip(unsigned int length)
            {
                return ConnectionStream::skip(length);
            }

            void setRecvBytsFN(boost::function<void(unsigned int)> fn)
            {
                recvBytsFN_ = fn;
            }

        private:
            boost::function<void(unsigned int)> recvBytsFN_;
        };

    }
}

#endif //NIO_NET_CONNECTIONINPUTSTREAM_HPP_
